package client;

import util.Utility;

public class QQView {

    private boolean flag = true;
    private String key;
    private UserClientService userClientService = new UserClientService();

    public void  mainMenu()
    {
        while (flag)
        {
            System.out.println("========欢迎登录网络通信系统=======");
            System.out.println("\t\t 1 登录系统");
            System.out.println("\t\t 9 退出系统");
            System.out.print("请输入你的选择：");
            key = Utility.readString(1);
            switch (key)
            {
                case "1":
                    System.out.print("请输入用户号");
                    String userId = Utility.readString(50);
                    System.out.print("请输入密  码");
                    String pwd = Utility.readString(50);
                    //从服务端获取校验账号密码
                    if (userClientService.userAuthentication(userId,pwd))
                    {

                        while (flag)
                        {
                            System.out.println("\n=========网络通信系统二级菜单（用户"+userId+"）======");
                            System.out.println("\t\t 1 显示在线用户列表");
                            System.out.println("\t\t 2 群发消息");
                            System.out.println("\t\t 3 私聊消息");
                            System.out.println("\t\t 4 发送文件");
                            System.out.println("\t\t 9 退出系统");
                            System.out.println("请输入你的选择:");
                            key = Utility.readString(1);
                            switch (key)
                            {
                                case "1" :
                                    userClientService.getOnline(userId);
                                    break;
                                case "2" :
                                    System.out.println("请输入你想群发的话:");
                                    String groupMes = Utility.readString(50);
                                    userClientService.groupChat(userId,groupMes);
                                    break;
                                case "3" :
                                    System.out.println("请输入你想私聊的用户Id:");
                                    String target = Utility.readString(50);
                                    System.out.println("请输入你想私聊的话:");
                                    String mes = Utility.readString(50);
                                    userClientService.privateChat(userId,target,mes);
                                    break;
                                case "4" :
                                    System.out.println("请输入想要传输文件的路径（D:\\dundun.jpg）:");
                                    String url = Utility.readString(50);
                                    System.out.println("请输入你想发送的用户Id:");
                                    String targetUser = Utility.readString(50);
                                    userClientService.sendFile(userId,targetUser,url);
                                    break;
                                case "9" :
                                    System.out.println("退出系统");
                                    flag = false;
                                    userClientService.loginOut(userId);
                                    System.exit(0);
                                    break;
                            }

                        }
                    }
                    break;
                case "9":
                    System.out.println("退出系统");
                    System.exit(0);
                    flag = false;
                    break;
            }

        }
    }

}
